import sys
import time

# 账户数据源
bank = {
    'users':['Tom','Jack','Lucy'],
    'pwd': ['123', '456','789'],
    'money':[1000,2000,3000],
    'history':[[],[],[]]
}

# 界面操作
while True:
    print('='*12+'欢迎使用ATM存取款管理系统!'+'='*12)
    # 登录验证
    user_now_name = str(input("请输入您的用户名："))
    if user_now_name in bank['users']:
        user_index = bank['users'].index(user_now_name)
        # 判断密码是否匹配
        while True:
            user_now_pwd = str(input("请输入您的密码：\n"))
            if user_now_pwd == bank['pwd'][user_index]:
                print('登录成功！')
                isLogin = True
                bank['history'][user_index].append(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + '         登陆系统')
                break
            else:
                print('密码错误，请重试！\n')
        break
    else:
        print('抱歉，不存在该用户，请先注册账户！\n')


while isLogin:
    # 显示主界面
    print('=' * 12, 'ATM存取款管理系统', '=' * 12)
    print('{0:1}{1:13}{2:15}'.format(' ', '1.自助取款', '2.自助存款'))
    print('{0:1}{1:13}{2:15}'.format(' ', '3.查询余额', '4.退出系统'))
    print('=' * 40)
    service_num = int(input('请输入对应的选择：'))
    if service_num == 1:
        # 进入存款界面
        money_out = int(input('请输入取款金额：'))
        if money_out > 0 and money_out < int(bank['money'][user_index]):
            bank['money'][user_index]  = int(bank['money'][user_index]) - money_out
            print('账户余额：', bank['money'][user_index])
            bank['history'][user_index].append(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + '         取款' + str(money_out))
        else:
            print('当前余额不足！！')
    elif service_num == 2:
        # 进入取款界面
        money_in = int(input('请输入存款金额：'))
        if money_in < 0:
            print('存款金额必须大于0')
        else:
            bank['money'][user_index]  = int(bank['money'][user_index]) + money_in
            print('账户余额：', bank['money'][user_index])
            bank['history'][user_index].append(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + '         存款' + str(money_in))
    elif service_num == 3:
        # 显示账户余额
         print('账户余额：', bank['money'][user_index])
    elif service_num == 4:
        # 退出系统
         bank['history'][user_index].append(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + '         退出系统')
         print('再见！！！')
         break
    else:
        print('请输入1-4')